#!/bin/bash
rm -rf kooder
git clone https://gitee.com/hellohank/kooder.git
#在当前目录下如果有kooder.properties文件，那下面这个操作就不需要了
cp kooder.properties kooder/gateway/src/main/resources/
cd kooder
mvn clean package -Dmaven.test.skip=true || exit -127


(ps -ef | grep kooder-gateway.jar | grep -v grep | awk '{print $2}' | xargs kill -9)||(echo "")

nohup java -cp gateway/target/kooder-gateway.jar com.gitee.kooder.server.Gateway > run.log 2>&1 &


APP_PORT=8002
STATUS=1
for i in `seq 1 120`;do
    code=`curl -I http://127.0.0.1:${APP_PORT}/monitor --connect-timeout 2|grep HTTP|awk '{print $2}' 2>/dev/null`
    if [[ ${code} -eq 200 ]];then
      STATUS=0
      echo "timo started successfully !"
      break
    else
      sleep 1
    fi
done

if [[ STATUS -eq 0 ]];then
    echo "启动成功"
else
    echo "启动失败"
    pwd
    cat run.log
    exit -127
fi